package homework;

import java.util.Random;
import java.util.Scanner;

public class Day04 {
    public static void main(String[] args) {
        //commandBySwitch();
        //guessingWhile();
        guessingDoWhile();
    }

    public static void commandBySwitch(){
        Scanner scan = new Scanner(System.in);
        System.out.println("转接请按1，缴费请按2，人工接听请按0");
        int num = scan.nextInt();
        switch (num){
            case 1:
                System.out.println("正在进行转接");
                break;
            case 2:
                System.out.println("正在进行缴费跳转");
                break;
            case 0:
                System.out.println("正在转接人工");
                break;
            default:
                System.out.println("按键错误");
        }
    }

    public static void guessingWhile(){
        //获取随机数
        int num = (int)(Math.random()*1000);
        System.out.println("作弊中：随机数是"+num);
        Scanner scan = new Scanner(System.in);
        while(true){
            System.out.println("请猜吧！");
            int guessNum = scan.nextInt();
            if(num == guessNum){
                System.out.println("猜对了，正确数字是："+num);
                break;
            }else if(num > guessNum){
                System.out.println("太小了");
            }else{
                System.out.println("太大了");
            }
        }
    }

    public static void guessingDoWhile(){
        //获取随机数
        //int num = (int)(Math.random()*1000);

        Random random = new Random();
        int num = random.nextInt(1000);
        System.out.println("作弊中：随机数是"+num);
        Scanner scan = new Scanner(System.in);
        do{
            System.out.println("请猜吧！");
            int guessNum = scan.nextInt();
            if(num == guessNum){
                System.out.println("猜对了，正确数字是："+num);
                break;
            }else if(num > guessNum){
                System.out.println("太小了");
            }else{
                System.out.println("太大了");
            }
        }while(true);
    }
}
